<?php
/** 初始化项目 */
require '../../app/app.php';
/** 初始化数据库 */
use app\util\Mysql;
$database = Mysql::init();


if (isset($_SESSION['username']) && $_SESSION['username'] != "") {
    $out = array('code' => '0', "msg" => "", "count" => "", "data" => ""); //定义返回数组
    $limit = isset($_POST['limit']) ? intval($_POST['limit']) : 5;
    $page = isset($_POST['page']) ? intval($_POST['page']) : 1;
    $offset = $limit * ($page - 1);
    $page = ($_POST["page"] - 1) * $_POST["limit"]; //数组以0起始
    $limit = $_POST["limit"];
    $list = $database->select("user_login_info", ["id", "username","ip","logintime","ok","content"], ["LIMIT" => [$page, $limit]]);
    $count = $database->count("user_login_info");
    for($i=1;$list[$i-1]["id"]!=NULL;$i++){
        $list[$i-1]["logintime"]=date("Y-m-d H:i:s",$list[$i-1]["logintime"]);
    }
    $out["count"] = $count;
    $out["data"] = $list;
    echo json_encode($out);
} else {
    $out = array('code' => '1', "msg" => "请先登录", "count" => "", "data" => ""); //定义返回数组
    echo json_encode($out);
}
?>

